package com.pi.tools;


/**
 *  
 * 
 * @author rls
 * @company canyou
 */

public class Page {

	private final static int DEFAULT_PAGE_SIZE = 10;

	private  int pageSize = DEFAULT_PAGE_SIZE; //  

	private long start=0; //  

	private Object data=null; //  
	private  int pageIndex=1;  // 
	private long totalCount=0; //  
	@SuppressWarnings("unused")
	private long pagemax;// 
	private Object AllData = null;
	private String sfdc = "0";// 
	
	public void setSfdc(String sfdc) {
		this.sfdc = sfdc;
	}
	public String getSfdc() {
		return sfdc;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public long getPagemax() {
		return getTotalPageCount();
	}
	public long getStart() {
		return start;
	}
	public void setStart(long start) {
		this.start = start;
	}
	 
	public int getPageIndex() {
		return this.pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Page() {
		
	}

	public Page(long start, long totalCount, int pageSize, Object data,Object AllData) {
		this.start = start;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.data = data;
		this.AllData = AllData;
		this.pageIndex = Integer.valueOf(String.valueOf(getCurrentPageNo())); 
	}
	
	 
	public long getTotalCount() {
		return this.totalCount;
	}
	 
	public Object getResult() {
		return this.data;
	}
	public Object getAllResult(){
		return this.AllData;
	}
	 
	public int getPageSize() {
		return this.pageSize;
	}
	 
	public long getTotalPageCount() {
		return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount
				/ pageSize + 1;
	}
	
	 
	public long getCurrentPageNo(){
		return start/pageSize+1;
	}
	 
	public boolean hasNextPage() {
		return this.getCurrentPageNo() < this.getTotalPageCount() - 1;
	}

	 
	public boolean hasPreviousPage() {
		return this.getCurrentPageNo() > 1;
	}

	 
	protected static int getStartOfPage(int pageNo) {
		return getStartOfPage(pageNo, DEFAULT_PAGE_SIZE);
	}

	 
	public static int getStartOfPage(int pageNo, int pageSize) {
		return (pageNo - 1) * pageSize;
	}
	public void setPagemax(long pagemax) {
		this.pagemax = pagemax;
	}
	
}
